/*
 * PURION_Login.java
 *
 * Created on 2008년 1월 8일 (화), 오전 2:25
 */

package PuriON;

import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author  hyukmini
 */
public class PURION_Login extends javax.swing.JFrame {
    
    private PURION_Main parent = null;
    
    
    /** Creates new form PURION_Login */
    public PURION_Login(PURION_Main p) {
        
        parent = p;
        initComponents();
        this.setVisible(true);
        this.setLocation((int) Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - this.getWidth() / 2,
                (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 - this.getHeight() / 2);
    }
    boolean processing = false;
    
    /* 데이터 베이스내에 사용자가 존재하면 존재하지 않으면 등록 메세지 */
    public void sendQuery() {
        
        String id = idField.getText();
        String query = "SELECT * FROM User where ID = '" + id + "'";
      
        PURION_Connect loginquery = null;
        
        loginquery = new PURION_Connect(parent);
        
        
        //08.05.30 이진우 PURION_Connect 수정중 추가 부분
        //로그인시 정상적인 리턴값은 :ANS
        if(loginquery.sendMessage(query).equals(":ANS")){
            parent.setVisible(true);
            dispose();
        }
        switchEnable();
        parent.setLoginID(id);
        
    }
    
    public void switchEnable() {
        if (processing == true) {
            idField.setEditable(true);
            idField.setEnabled(true);
            
            jButton2.setVisible(true);

            
            processing = false;
        }
        else {
            idField.setEditable(false);
            idField.setEnabled(false);
            
            jButton2.setVisible(false);

            processing = true;
        }

    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        idField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("로그인");
        setResizable(false);

        jButton1.setText("등록");
        jButton1.setBounds(40, 170, 60, 23);
        jLayeredPane2.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton2.setText("로그인");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jButton2.setBounds(109, 170, 80, 23);
        jLayeredPane2.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("메일주소");
        jLabel2.setBounds(40, 120, 70, 15);
        jLayeredPane2.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        idField.setBounds(40, 140, 150, 21);
        jLayeredPane2.add(idField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/PuriON/reources/first.png"))); // NOI18N
        jLabel3.setText("jLabel3");
        jLabel3.setBounds(0, 0, 380, 230);
        jLayeredPane2.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.sendQuery();
    }//GEN-LAST:event_jButton2ActionPerformed

    
    
    /**
     * @param args the command line arguments
     */

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField idField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLayeredPane jLayeredPane2;
    // End of variables declaration//GEN-END:variables

    
}
